package com.compmov.socialnetwork;

import java.util.List;

import com.compmov.datamodel.Persona;
import com.compmov.libraries.LazyAdapter;
import com.compmov.webservice.PersonaWSClient;
import com.compmov.webservice.WSClientException;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.widget.ListView;
import android.widget.Toast;

public class Amigos extends Activity {

	private ListView list;
	LazyAdapter adapter;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.amigos);

		list = (ListView) findViewById(R.id.list);
		PersonaWSClient personaWS = new PersonaWSClient("persona");
		try{
			List<Persona> personas=personaWS.getAllFriends(com.compmov.libraries.Utils.getPersona());
			adapter = new LazyAdapter(this, personas);
			list.setAdapter(adapter);
		
		} catch (WSClientException e) {
			Toast.makeText(getBaseContext(),"Error en el servidor. Intente de nuevo",
					Toast.LENGTH_SHORT).show();
		}
		


	}

	@Override
	public void onDestroy() {
		adapter.imageLoader.stopThread();
		list.setAdapter(null);
		super.onDestroy();
	}




    @Override
	public boolean onCreateOptionsMenu(Menu menu) {
		MenuInflater inflater = getMenuInflater();
		inflater.inflate(R.menu.menu_amigos, menu);
		return true;
	}
    
//  @Override
	public boolean onOptionsItemSelected(MenuItem item) {
		Intent intent;
		switch (item.getItemId()) {
		case R.id.itemAddAmig:
			 intent = new Intent(this.getApplicationContext(),BuscarAmigos.class);
			 startActivity(intent);   		                     
			return true;
		case R.id.itemBuscAmig:
			 intent = new Intent(this.getApplicationContext(),BuscarAmigos.class);
			 intent.putExtra("idPer", com.compmov.libraries.Utils.getPersona().getId());
			 startActivity(intent);   		                     
			return true;
		case R.id.itemSol:
			 intent = new Intent(this.getApplicationContext(),Solicitudes.class);
			 startActivity(intent);   		                     
			return true;
		default:
			return super.onOptionsItemSelected(item);
		}
	}
	
}
